import React from 'react';
import { useRequest } from '@/hooks';
import { getRecruitmentInfo } from '@/pages/Organization/EmployeeManage/services';
import { Alert, Empty, Skeleton } from 'antd';
import RecruitmentSection from '@/pages/Organization/EmployeeManage/components/EmployeeInfoSections/RecruitmentSection';

/**
 * 员工详情 - 应聘记录
 */
const RecruitmentTabContent = ({ employeeCode }) => {
    // 固定资产数据
    const { data: recruitmentData, loading: recruitmentLoading, error: recruitmentError } = useRequest(
        () => getRecruitmentInfo({ employeeCode }),
        {
            cacheKey: `employee-recruitment-${employeeCode}`,
            refreshDeps: [employeeCode],
            formatResult: res => {
                if (res) {
                    const { code, data } = res;
                    if (code === 10000) {
                        return data;
                    }
                }
                return undefined;
            }
        }
    );

    // 错误处理
    if (recruitmentError) {
        return <Alert type="error" message={recruitmentError?.msg || '数据加载错误'} />;
    }

    // render
    return (
        <Skeleton loading={recruitmentLoading} active>
            {/* 应聘记录 */}
            {recruitmentData ? (
                <RecruitmentSection formData={recruitmentData} />
            ) : (
                <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
            )}
        </Skeleton>
    );
};

export default RecruitmentTabContent;
